<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\Dashboard;
use Encore\Admin\Layout\Column;
use Encore\Admin\Layout\Content;
use Encore\Admin\Layout\Row;
use App\Models\UserLog;
use App\Models\Order;

class HomeController extends Controller
{
    public function index(Content $content)
    {
        // return $content
        //     ->title('Dashboard')
        //     ->description('Description...')
        //     ->row(Dashboard::title())
        //     ->row(function (Row $row) {

        //         $row->column(4, function (Column $column) {
        //             $column->append(Dashboard::environment());
        //         });

        //         $row->column(4, function (Column $column) {
        //             $column->append(Dashboard::extensions());
        //         });

        //         $row->column(4, function (Column $column) {
        //             $column->append(Dashboard::dependencies());
        //         });
        //     });
        $yes = date("Y-m-d",strtotime("-1 day"));
        $data = [];
        $data['yes_cz'] = UserLog::where('type',12)->where('currency_type','=','balance')->where('created_at','>',$yes.' 00:00:00')->where('created_at','<',$yes.' 23:59:59')->sum('in');
        $data['today_cz'] = UserLog::where('type',12)->where('currency_type','=','balance')->where('created_at','>',date('Y-m-d').' 00:00:00')->where('created_at','<',date('Y-m-d').' 23:59:59')->sum('in');
        $data['total_cz'] = UserLog::where('type',12)->where('currency_type','=','balance')->sum('in');
        
        $data['yes_tx'] = UserLog::where('type',13)->where('currency_type','=','balance')->where('created_at','>',$yes.' 00:00:00')->where('created_at','<',$yes.' 23:59:59')->sum('out');
        $data['today_tx'] = UserLog::where('type',13)->where('currency_type','=','balance')->where('created_at','>',date('Y-m-d').' 00:00:00')->where('created_at','<',date('Y-m-d').' 23:59:59')->sum('out');
        $data['total_tx'] = UserLog::where('type',13)->where('currency_type','=','balance')->sum('out');
        
        $data['yes_tb'] = UserLog::where('type',43)->where('currency_type','=','btc')->where('created_at','>',$yes.' 00:00:00')->where('created_at','<',$yes.' 23:59:59')->sum('out');
        $data['today_tb'] = UserLog::where('type',43)->where('currency_type','=','btc')->where('created_at','>',date('Y-m-d').' 00:00:00')->where('created_at','<',date('Y-m-d').' 23:59:59')->sum('out');
        $data['total_tb'] = UserLog::where('type',43)->where('currency_type','=','btc')->sum('out');
        
        $data['yes_dh'] = UserLog::where('type',41)->where('currency_type','=','btc')->where('created_at','>',$yes.' 00:00:00')->where('created_at','<',$yes.' 23:59:59')->sum('out');
        $data['today_dh'] = UserLog::where('type',41)->where('currency_type','=','btc')->where('created_at','>',date('Y-m-d').' 00:00:00')->where('created_at','<',date('Y-m-d').' 23:59:59')->sum('out');
        $data['total_dh'] = UserLog::where('type',41)->where('currency_type','=','btc')->sum('out');
        
        $data['yes_df'] = UserLog::where('type',32)->where('currency_type','=','electricity_fee')->where('created_at','>',$yes.' 00:00:00')->where('created_at','<',$yes.' 23:59:59')->sum('out');
        $data['today_df'] = UserLog::where('type',32)->where('currency_type','=','electricity_fee')->where('created_at','>',date('Y-m-d').' 00:00:00')->where('created_at','<',date('Y-m-d').' 23:59:59')->sum('out');
        $data['total_df'] = UserLog::where('type',32)->where('currency_type','=','electricity_fee')->sum('out');
        
        $data['yes_sl'] = Order::where('status','=',1)->where('created_at','>',$yes.' 00:00:00')->where('created_at','<',$yes.' 23:59:59')->sum('computing');
        $data['today_sl'] = Order::where('status','=',1)->where('created_at','>',date('Y-m-d').' 00:00:00')->where('created_at','<',date('Y-m-d').' 23:59:59')->sum('computing');
        $data['total_sl'] = Order::where('status','=',1)->sum('computing');
       // $total_btc = UserLog::where('type',42)->where('currency_type','=','btc')->where('user_id',$user->id)->sum('in');
        
        return $content->view('detail',['data'=>$data]);
    }
}
